﻿var thisWidget;
function initWidgetView(t) {
    (thisWidget = t).config && thisWidget.config.style && $("body").addClass(thisWidget.config.style),
        $("#btnFlyStop").click(function (t) {
            thisWidget.toRoamLine()
        }), 
        $("#btnSelChars").click(function (t) {
            thisWidget.showHeightChars()
        });
        
    var e = thisWidget.getAttr();
    $("#cameraType").attr("data-value", e.camera.type),
        $("#followedX").val(e.camera.followedX),
        $("#followedZ").val(e.camera.followedZ),
        $("#cameraType").select(),
        $("#cameraType").change(function () {
            switch ($("#tr_followedX").hide(),
            $("#tr_followedZ").hide(),
            $(this).attr("data-value")) {
                case "dy":
                    $("#tr_followedX").show(),
                        $("#tr_followedZ").show(),
                        $("#followedX").val(10),
                        $("#followedZ").val(2);
                    break;
                case "sd":
                    $("#tr_followedZ").show(),
                        Number($("#followedZ").val()) < 500 && $("#followedZ").val(100)
            }
            updateCameraSetting()
        }),
        $("#cameraType").change(),
        $("#followedX").change(function () {
            updateCameraSetting()
        }), $("#followedZ").change(function () {
            updateCameraSetting()
        })
}
function updateCameraSetting() {
    var t = $("#cameraType").attr("data-value"),
        e = Number($("#followedX").val()),
        l = Number($("#followedZ").val());
    thisWidget.updateStyle({
        camera: {
            type: t,
            followedX: e,
            followedZ: l
        }
    })
}
var _alltime = 100;
function showAllInfo(t) {
    _alltime = t.alltime, $("#td_name").html(t.name), $("#td_alltimes").html(haoutil.str.formatTime(t.alltime)), $("#td_alllength").html(haoutil.str.formatLength(t.alllen))
}
function showRealTimeInfo(t) {
    var e = Math.ceil(100 * t.time / _alltime);
    e < 1 && (e = 1), 100 < e && (e = 100), $(".progress-bar").css("width", e + "%").attr("aria-valuenow", e).html(e + "%"), $("#td_jd").html(t.x), $("#td_wd").html(t.y), $("#td_gd").html(haoutil.str.formatLength(t.z)), $("#td_times").html(haoutil.str.formatTime(t.time)), $("#td_length").html(haoutil.str.formatLength(t.len)), t.hbgd ? $("#td_dmhb").html(haoutil.str.formatLength(t.hbgd)) : $("#td_dmhb").html("未知"), t.ldgd ? $("#td_ldgd").html(haoutil.str.formatLength(t.ldgd)) : $("#td_ldgd").html("未知")
} ! function (o) {
    var e = {
        select: "mp_select",
        select_text: "mp_select_text",
        select_ul: "mp_select_ul"
    };
    o.fn.extend({
        select: function (t) {
            var d = o.extend({}, e, t);
            return this.each(function () {
                var l = o(this);
                void 0 !== l.data("value") && "" !== l.data("value") && l.val(l.data("value"));
                var e = [];
                e.push('<div class="' + l.attr("class") + '">'), e.push('<div class="' + d.select_text + '">' + l.find(":selected").text() + "</div>"), e.push('<ul class="' + d.select_ul + '">'), l.children("option").each(function () {
                    var t = o(this);
                    l.data("value"), t.val(), e.push('<li data-value="' + t.val() + '">' + t.text() + "</li>")
                }), e.push("</ul>"), e.push("</div>");
                var t = o(e.join("")),
                    a = t.find("." + d.select_text),
                    i = t.find("." + d.select_ul);
                l.after(t), l.hide(), l.change(function () {
                    var e = l.attr("data-value");
                    l.children("option").each(function () {
                        var t = o(this);
                        e == t.val() && a.text(t.text())
                    })
                }), t.click(function (t) {
                    o(this).toggleClass("mp_selected"), o(this).find("." + d.select_ul).slideToggle().end().siblings("div." + d.select).find("." + d.select_ul).slideUp(), t.stopPropagation()
                }), o("body").click(function () {
                    i.slideUp()
                }), i.on("click", "li", function () {
                    var t = o(this),
                        e = t.addClass("selecton").siblings("li").removeClass("selecton").end().data("value").toString();
                    e !== l.attr("data-value") && (a.text(t.text()), l.attr("data-value", e), l.change())
                })
            })
        }
    })
}(jQuery);